Repository navigation
fix: record tool definitions in the semconv function-tool shape and skip unnamed tool calls - #286
PabloPardoGarcia wants to merge 5 commits into
Conversation
…kip unnamed tool calls
A function tool is now recorded as {type: function, name, description,
parameters}: OpenAI's nested function is lifted, Anthropic's input_schema
(and the legacy functions entries) become function tools with parameters.
A provider's built-in tool keeps its fields, with its type prefixed by the
provider name. Applied on set_tool_definitions and on the definitions the
normalizer reassembles from OpenInference and the request bag.
A tool call with no string name is skipped rather than written with
name: null, which the conventions' schema rejects.
Automated reviewNo blocking issues. The mapping is sound, What I checked
Good calls
Should fix1. Nameless 2. Skipping drops the call's 3. Some real shapes are still schema-invalid after normalization (from the probe):
None of these is a regression, because they were invalid before too. If they become follow-ups, the semconv rationale in rius-semconv#114 should not claim "whatever the provider's spelling". 4. The SDK and the sink will diverge until the sink adopts the rule. argus-core Nits
|
…mini tool definitions A tool call without a name is written as a text part holding its id and arguments instead of being dropped, on every path that writes tool_call parts. Bedrock toolSpec definitions become function tools, and Gemini function declarations expand to one function tool each.
|
Addressed in 6e9ad51:
Nit (context sizes): noted for the release notes. ruff, mypy and pytest (2931 passed) are green locally. |
Automated reviewNo blocking issues. The mapping is right for every real provider shape I fed it, and the output is byte-identical to rius-sdk-typescript#251 and argus-core#765. The two known issues (Gemini idempotence, empty list vs. sink) are confirmed below, with a fix, and they are the same in all three PRs. A few smaller edge cases follow. What I checked
Idempotence, the general form of the known Gemini issue. The Gemini expansion emits two kinds of entries that never go through the single-tool rule: nameless declarations and the leftover members. When the single-tool rule would rewrite one of them, the second pass changes it. Reproduced identically in all three languages:
Proposed fix, the same in all three. I applied it to a scratch copy of the Python module: the corpus becomes idempotent and
Empty lists, the known sink-vs-SDK issue (wider than Gemini). For the reassembly paths, the SDKs write Locations here: Should fix
Suggestions
Nits
Context-size shift: it is expected and covered by the conformance entries. It goes in the release notes as noted earlier. |
Every Gemini declarations spelling that holds a list expands, a declaration's schema is renamed from any spelling, and nameless declarations and the rest of a Gemini tool take the single-tool rule, so rewriting an output changes nothing. A nested function is lifted only without a top-level name, a null parameters gives way to another schema spelling, and an empty type gets no prefix. An MCP tool's headers are dropped, since they can carry credentials. Definitions that come to an empty list write nothing, as the sink does, and set_tool_definitions records a pydantic tool as its set fields. The shared rius-semconv tool_definitions cases are vendored and run.
|
Addressed the review in 9d47941. The same changes went into all three implementations (rius-sdk-python#286, rius-sdk-typescript#251, argus-core#765):
Left as known and noted in the PR body: number text and TypeScript's integer-key order outside canonical JSON, and a custom mask not seeing a nameless call's arguments inside the text part.
|
Automated review (follow-up, 9d47941)No blocking issues. Every should-fix, suggestion and nit from the previous review is fixed, and the TypeScript (#251) and sink (#765) ports were changed in lockstep. One credential field is still missed by the new MCP drop (item 1). What I checked
Should fix
Suggestions
Nits
|
…reat an empty tool name as none OpenAI's MCP tool carries authorization, an OAuth access token, beside headers: both go for mcp and any <provider>.mcp type, read from the type the tool is written with so a second pass drops the same members. A Chat Completions custom tool's nested fields are lifted by the function rule and it stays a custom tool. An empty name no longer makes a function tool. Only google-genai's pydantic models are dumped; other pydantic tools are recorded as before. Shared cases re-vendored from rius-semconv#117.
|
Addressed in
Also: Chat Completions Tests were written first and failed before the change. The shared cases are re-vendored from rius-semconv#117 |
The AI SDK's openai.mcp provider tool holds authorization and headers in args. A tool written as mcp or <provider>.mcp now loses them there as well as at the top level. Shared cases re-vendored from rius-semconv#117.
|
Landed through #289, together with the rius-semconv v1.13.0 sync. |
Two upstream schema changes in the GenAI conventions make part of what we record invalid: semantic-conventions-genai #608 (a
type: "function"tool definition must match the function-tool schema) and #584 (a message part with a knowntypecan no longer fall back to the generic part).Tool definitions
gen_ai.tool.definitionsis now written in the conventions' shape, onset_tool_definitions/tools=and on the definitions the normalizer reassembles from OpenInference (llm.tools.N.tool.json_schema) and the request bag (tools/functions). The rules live inrius/_tool_definitions.py:{type: "function", function: {...}}is lifted to{type: "function", name, description, parameters, ...}.nameand notype(Anthropic custom tools, OpenAI's legacyfunctions), or Anthropic's explicittype: "custom"withinput_schema, becomes a function tool.input_schema/inputSchemais renamed toparametersin place.{toolSpec: {name, description, inputSchema: {json: ...}}}is unwrapped to a function tool,inputSchema.jsonasparameters.{function_declarations: [...]}/{functionDeclarations: [...]}expands to one function tool per declaration, the schema taken fromparametersor elseparametersJsonSchema/parameters_json_schema/input_schema/inputSchema. A nameless declaration, and anything else in the Gemini tool (a built-in such asgoogle_search), follows as its own entry, rewritten by the single-tool rules.typeis a provider built-in tool. Its fields are kept and its type is prefixed with the provider (gen_ai.provider.name), as #608 recommends:anthropic.web_search_20250305. A type that already contains a dot is left alone, so a second pass never stacks prefixes. No provider, no prefix.name(OpenAIweb_search_preview, Geminigoogle_search) gets none invented, on purpose: tool names are read as the tools the model was offered, and an invented name would show up as a tool offered and never called. Such an entry still fails the upstreamGenericToolDefinitionschema, which requiresname.cachePoint) is kept as it is.Normalizing twice equals normalizing once. Context sizes are measured from the recorded (normalized) definitions, so tool-definition byte counts change slightly.
Tool calls without a name
The conventions require
nameon atool_callpart, so omitting the key would still be invalid. A tool call whose name is missing, empty or not a string is now written as a text part holding the call's JSON ({"id", "arguments"}, each left out when absent), the way the SDK already keeps content it has no part type for. Nothing is dropped, and a latertool_call_responsestill finds its id. This applies on both writers: the generation helper and the OpenInference reassembly (normalization.py). The sharedopeninference_messages.jsonfixture has a new case and updated expectations for calls without a name. The sink adopts the same rule in its own change.Conformance
The shared rius-semconv expected results still hold the provider shapes, so the 12 OpenInference families are listed in
tests/conformance/known_differences.jsonforgen_ai.tool.definitions. Those expected results get regenerated in rius-semconv from this SDK once it is released, and the entries go in that re-sync.Tests
New
tests/test_tool_definitions.py(including Bedrock, Gemini snake/camel case, Gemini built-ins beside declarations, idempotence over all of them); generation, normalization, instrumentation, crash-safety and span-limit tests updated to the new shape.ruff check,ruff format --check,mypyandpytestwere green at the first commit; see below for the follow-ups. Outputs checked byte-identical with the TypeScript port on a shared set of inputs, including the Bedrock and Gemini shapes.Review follow-ups (second commit)
All three implementations (this PR, glassflow/rius-sdk-typescript#251 and glassflow/argus-core#765) take the same changes, and rius-semconv's new shared cases hold them to the same bytes.
parametersJsonSchema,parameters_json_schema,input_schemaorinputSchema. Nameless declarations and the rest of a Gemini tool now go through the single-tool rule instead of being appended raw. Rewriting any output changes nothing.function. It is lifted only when the tool has no top-level stringname, so{"name":"x","function":{...}}keeps its name on every pass.parameters: nullcounts as no schema: when another spelling holds one, the null goes and that spelling is renamed (a Pythonmodel_dump()of a Gemini declaration holds both).type: ""gets no provider prefix, the same as a non-string type.type: "mcp"tool (also once namespaced asopenai.mcp) loses itsheadersmember. Those are the requests' headers to the MCP server and can carry anAuthorizationcredential, and credentials never belong in telemetry, content capture or not."tools": [], or a Gemini tool with no declarations), the OpenInference and request-bag paths write nogen_ai.tool.definitions, and still remove the sources.set_tool_definitionsis unchanged and writes what it is given.set_tool_definitionsrecords a pydantic model (google-genai'stypes.Tool) asmodel_dump(mode="json", exclude_none=True)instead of its repr. A model whose dump raises is kept as given.Shared cases
sdk_cases/tool_definitions.jsonis new in glassflow/rius-semconv#117: real provider shapes (OpenAI chat and Responses, Anthropic, Gemini, Bedrock, Vercel AI SDK, MCP) and the edge cases above, with expected results from the Python SDK. Every case asserts that a second pass writes the same bytes as the first. It is vendored here from that PR's head (8db007b) astests/fixtures/semconv/sdk_cases/tool_definitions.json. After rius-semconv#117 is squash-merged, re-sync it from rius-semconvmain(scripts/sync-semconv-fixtures.sh).Known, not changed here
1.0, TypeScript1, the sink keeps the producer's text), and TypeScript orders integer-like keys first. The shared cases hold no float and no integer-like key.maskthat redactsparts[].argumentsdoes not see a nameless call's arguments, which sit inside the text part'scontentstring. Worth a line in the masking docs or release notes.Tests (follow-ups)
New unit tests for each follow-up in
tests/test_tool_definitions.py, the empty-list rule on every normalizer route intests/test_normalization_tools.py, the pydantic model intests/test_generation.py, andtests/test_sdk_cases.pyruns the shared cases (38, once and twice). The shared cases failed 10 of 38 before the fix.ruff check,ruff format --check,mypyandpytest(2985 passed) exit 0.Review follow-ups (third commit)
In step with glassflow/rius-sdk-typescript#251 and glassflow/argus-core#765; rius-semconv#117 pins each rule with shared cases, re-vendored here from its head
8db007b.authorization. OpenAI's MCP tool also carriesauthorization, an OAuth access token for the remote server or connector. It is now dropped withheaders, formcpand any provider-prefixed<provider>.mcptype (openai.mcp,azure.mcp). The drop reads the type the tool is written with, so a Vercelprovidertool whoseidisopenai.mcploses them on the first pass, as it would on the second. Other tools keep anauthorizationmember.customtools.{"type":"custom","custom":{"name","description","format"}}has its nested members lifted to the top level when the tool has no top-level name (the same rule asfunction), and stays a non-function tool with the provider-prefixed type:{"type":"openai.custom","name":...,"format":...}, the same shape as the Responses custom tool. Anthropic'stype: "custom"withinput_schemastays a function tool, and the lifted tool goes through the same rule, so a nestedcustomholdinginput_schemais a function tool with or without a provider.{"name":""}(and an empty name on acustomtool withinput_schema, a BedrocktoolSpecor a Gemini declaration) no longer becomes a function tool with an empty name; it is kept as given, as an empty-named tool call is not atool_callpart. A nestedfunctionis lifted over an empty top-level name._plain. Only pydantic models from google-genai (a class whose module isgoogle.genaior under it) are dumped. Any other object, such as a LangChainStructuredTool, is recorded as before.Tests first: new cases in
tests/test_tool_definitions.py(MCPauthorizationonmcp/openai.mcp/azure.mcpand a Vercel MCP tool, other tools keepingauthorization, the custom lift and its two neighbours, empty names) andtests/test_generation.py(a non-google-genai pydantic tool is not dumped; the google-genai stand-in now sits undergoogle.genai.types). They failed before the change.tests/test_sdk_cases.pyruns the 44 shared cases once and twice.ruff check,ruff format --check,mypy,scripts/sync-semconv.sh --checkandpytest(3006 passed, 22 skipped, 1 xfailed) exit 0.args. The Vercel AI SDK'sopenai.mcpprovider tool (@ai-sdk/openai 4.0.111) holdsauthorizationandheadersin itsargs, besideserverLabel,serverUrl,connectorId,requireApprovaland others. For a tool whose final type ismcp/<provider>.mcp, both are now dropped fromargstoo. Other tools'argsare untouched. Shared cases re-vendored from rius-semconv#1178db007b(45). Gate: ruff, mypy, sync check, pytest 3009 passed.Not in scope, as a follow-up: scrubbing credentials from definitions the rules do not rewrite. A span's native
gen_ai.tool.definitionswritten by another instrumentation, and raw request bodies (OpenInference / OpenLLMetryinput.value), keep an MCP tool'sheaders/authorization. Both are content-gated.Closes RIUS-1879